//
//  Timer.m
//  OralRobot
//
//  Created by 王桂敏 on 16/4/11.
//  Copyright © 2016年 huayingdai. All rights reserved.
//

#import "Timer.h"

@interface Timer ()

@property(nonatomic,strong) NSTimer *timer;

@end
@implementation Timer

// 单例方法
+ (id)defaultTimer{
    static Timer *timer = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        timer = [[self alloc] init];
    });
    return timer;
}
- (instancetype)init{
    self = [super init];
    if (self) {
        [self.timer class];
    }
    return self;
}
- (NSTimer *)timer{
    if (!_timer) {
        self.timer = [NSTimer scheduledTimerWithTimeInterval:1
                                                      target:self      selector:@selector(timerAction:) userInfo:nil
                                                     repeats:YES];

    }
    return _timer;
}

- (void)timerAction:(NSTimer*)timer{
    [self postNotificationName:kNotificationTimer object:self userInfo:nil];
    if (self.delegate && [self.delegate respondsToSelector:@selector(timer:)]) {
        [self.delegate timer:self];
    }
    
}

@end
